import App from './App';
import Vue from 'vue';
import './uni.promisify.adaptor';

Vue.prototype.headers = {
	'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
};
// 网络请求超时时间
Vue.prototype.timeout = 10000;

Vue.prototype.api_version = ''; //app接口版本
Vue.prototype.socketpath = '';
Vue.prototype.apiFilename = '/ajax' + Vue.prototype.api_version;
Vue.prototype.apiwss = 'wss://test.h5.qijiniu.com'; //
Vue.prototype.apiUrl = 'http://test.h5.qijiniu.com'; //api请求url
Vue.prototype.webUrl = 'http://test.h5.qijiniu.com'; //api请求url
Vue.prototype.webUrlss = 'http://test.h5.qijiniu.com'; //获取access_token
Vue.prototype.h5Url = 'http://test.h5.qijiniu.com'; //获取access_token

// Vue.prototype.api_version = ''; //app接口版本
// Vue.prototype.socketpath = '';
// Vue.prototype.apiFilename = '/ajax' + Vue.prototype.api_version;
// Vue.prototype.apiwss = 'wss://h5.qijiniu.com'; //
// Vue.prototype.apiUrl = 'https://h5.qijiniu.com'; //api请求url
// Vue.prototype.webUrl = 'https://h5.qijiniu.com'; //api请求url
// Vue.prototype.webUrlss = 'https://h5.qijiniu.com'; //获取access_token
// Vue.prototype.h5Url = 'https://h5.qijiniu.com'; //获取access_token

Vue.prototype.show_log = true;
Vue.prototype.show_data = true;
Vue.prototype.show_buffer = false;
Vue.prototype.test_role = false;
Vue.prototype.test_login = false;

// Vue.prototype.test_role = true;
// 蓝牙接收响应数据最后包   可能多个包
// 最长20个字节判断结束停止位 0x77并且长度校验

Vue.prototype.login_components_task = null;

Vue.prototype.bluetooth_read_temp = [];
Vue.prototype.bluetooth_can_write = true;

Vue.prototype.bluetooth_value_change_callback = null;
Vue.prototype.bluetooth_write_timeout_task = null;

Vue.prototype.main_change_var = {
	// 一次性函数
	once_req: false,
	repeat_once: true,
	page_canshow: false,
	isPay: false,
	isSelectFile: false,
	isScanning: false,
	timeout_loading: false,
	SCAN_QRCODE: '',

	// 扫描日志
	bluetooth_scan_log_list: [],
	pulldown: 0,

	//可视区域上方高度 如自定义导航
	page_top: 0,
	//可视区域下方高度 如悬浮按钮
	page_bot: 0,
	//可视区域切换标签高度
	page_nav: 0,
	page_content_top: 0,

	//触发导航条滚动变化阈值
	scrollTop_targe: 100,
	vh: 0,
	win_height: 0,

	//验证码发送频率
	page_iTime: 59,

	// 蓝牙某些不重要的数据暂存
	// 某个节点统一更新到 store中
	BLUETOOTH_DEVICE_TEMP: {},
};

// -------------  初始化
// Vue.prototype.checkphone = /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/; //验证手机号码正则
Vue.prototype.checkphone = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/; //验证手机号码正则

Vue.prototype.check_sn = /^[0-9]*$/; //验证电话正则

Vue.prototype.checkmobile = /^([0-9]{3,4}-)?[0-9]{7,8}$/; //验证电话正则
Vue.prototype.check_sfz = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; //验证身份证
Vue.prototype.check_name = /^[\u4e00-\u9fa5]{0,}$/; //验证姓名
Vue.prototype.check_number = /^(\-|\+)?\d+?$/; //验证正负数字

Vue.prototype.routerclick = true;

Vue.prototype.app_init = function () {
	let _this = this;
	uni.getSystemInfo({
		success(res) {
			// console.log(res);
			// console.log(menuButtonInfo);
			let winW = res.windowWidth;
			let data = {};

			// #ifdef MP-WEIXIN
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
			data[`statusBarHeight`] = _this.pxTorpx(menuButtonInfo.top, winW); // 状态栏高度
			// #endif

			// #ifdef APP-PLUS
			data[`statusBarHeight`] = _this.pxTorpx(res.statusBarHeight, winW); // 状态栏高度
			// #endif

			data['phone_info'] = `${res.model}(${res.system})`; // 设备系统
			data['platform'] = res.platform; // 设备系统
			data[`is_${res.platform}`] = true; // 设备系统判断值
			data['version'] = res.SDKVersion; // 程序版本（小程序版本）
			data['safeAreaInsets_bot'] = _this.pxTorpx(res.safeAreaInsets.bottom, winW); // IOS底部安全距离
			data['device_bot'] = _this.pxTorpx(res.safeAreaInsets.bottom || 10, winW); // 元素安全距离

			data['win_width'] = _this.pxTorpx(res.windowWidth, winW); // 屏幕宽度
			data['versionCode'] = res.appVersionCode; // 1000
			data['versionCode_show'] = res.appWgtVersion || res.appVersion; //展示作用的版本号 1.00.0

			_this.store_set_state_config({ state_name: 'COMMON_VAR', data });
		},
	});

	return Vue.prototype;
};
// -------------  初始化

// 公用js方法封装
import { common } from './util/method.js';

for (let k in common) {
	Vue.prototype[k] = common[k];
}

import store from './store/store.js';
Vue.prototype.$store = store;
App.mpType = 'app';
const app = new Vue({
	...App,
	store,
});
app.$mount();
